﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace AMDev.BNET.ClientAPI.WoW
{
    /// <summary>
    /// Represents a World of Warcraft character.
    /// </summary>
    /// <remarks>
    /// Thumbanails data can be found to the URL: http:// <region> + .battle.net/static-render/ + <region> + / + <the string you got from API as thumbnail> 
    /// </remarks>
    [DataContract]
    [KnownType(typeof(WoWCharacterStats))]
    public sealed class WoWCharacter
        : ClientObservableObject
    {        
        #region Fields

        private String realm;
        private String name;        
        private String avatarThumbnail;
        private String battlegroup;
        private int level;
        private int achievementPoints;
        private WoWRaces race;
        private WoWClasses characterClass;
        private WoWGenders gender;
        private WoWCharacterStats stats;

        #endregion

        #region Properties

        [DataMember(Name = "realm")]
        public String Realm
        {
            get
            {
                return this.realm;
            }
            set
            {
                this.SetProperty(ref this.realm, value);                
            }
        }

        [DataMember(Name = "name")]
        public String Name
        {
            get
            {
                return this.name;
            }
            set
            {
                this.SetProperty(ref this.name, value);                
            }
        }

        [DataMember(Name = "battlegroup")]
        public String Battlegroup
        {
            get
            {
                return this.battlegroup;
            }
            set
            {
                this.SetProperty(ref this.battlegroup, value);
            }
        }

        [DataMember(Name = "thumbnail")]
        public String AvatarThumbnail
        {
            get
            {
                return this.avatarThumbnail;
            }
            set
            {
                this.SetProperty(ref this.avatarThumbnail, value);
            }
        }

        public String CharacterRender
        {
            get
            {
                String result = null;
                if (!String.IsNullOrEmpty(this.AvatarThumbnail))
                    result = this.AvatarThumbnail.Replace("-avatar", "-profilemain");
                return result;
            }
        }

        [DataMember(Name = "level")]
        public int Level
        {
            get
            {
                return this.level;
            }
            set
            {
                this.SetProperty(ref this.level, value);
            }
        }

        [DataMember(Name = "achievementPoints")]
        public int AchievementPoints
        {
            get
            {
                return this.achievementPoints;
            }
            set
            {
                this.SetProperty(ref this.achievementPoints, value);
            }
        }

        [DataMember(Name = "gender")]
        public WoWGenders Gender
        {
            get
            {
                return this.gender;
            }
            set
            {
                this.SetProperty(ref this.gender, value);                
            }
        }

        [DataMember(Name = "race")]
        public WoWRaces Race
        {
            get
            {
                return this.race;
            }
            set
            {
                this.SetProperty(ref this.race, value);
            }
        }

        [DataMember(Name = "class")]
        public WoWClasses CharacterClass
        {
            get
            {
                return this.characterClass;
            }
            set
            {
                this.SetProperty(ref this.characterClass, value);
            }
        }

        // Optional values

        [DataMember(Name = "stats", IsRequired=false)]
        public WoWCharacterStats Stats
        {
            get
            {
                return this.stats;
            }
            set
            {
                this.SetProperty(ref this.stats, value);
            }
        }

        #endregion       

        #region Methods

        public override string ToString()
        {
            StringBuilder characterText = null;

            characterText = new StringBuilder();

            characterText.AppendFormat("Name: {0}", this.Name);
            characterText.AppendLine();
            characterText.AppendFormat("Realm: {0}", this.Realm);
            characterText.AppendLine();
            characterText.AppendFormat("Battlegroup: {0}", this.Battlegroup);
            characterText.AppendLine();
            characterText.AppendFormat("Race: {0}", this.Race.ToString());
            characterText.AppendLine();
            characterText.AppendFormat("Class: {0}", this.CharacterClass.ToString()); 
            characterText.AppendLine();
            return characterText.ToString();
        }

        #endregion
    }
}
